'use strict';
function checkToken() {
  return async function(ctx, next) {
    const token = ctx.request.header.token;
    const decode = ctx.app.jwt.verify(token, ctx.app.config.jwt.secret);
    console.log(decode);

    try {
      if (decode.username) {
        await next();
      } else {
        ctx.body = {
          code: '403',
          msg: '用户校验失败',
        };
      }
    } catch (e) {
      ctx.body = {
        code: '403',
        msg: 'token未通过验证',
      };
    }
  };
}

module.exports = checkToken;
